
public class p1006_4125ms_56th {

	public static//
	// -----
	// -----
	class Main {
		public static void main(String[] args) throws Exception {
			java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
			int i = 0;
			while (true) {
				String[] parts = reader.readLine().split(" ");
				int d = Integer.parseInt(parts[3]);
				if (d < 0)
					return;
				d = 21252 - d;

				int a = (Integer.parseInt(parts[0]) + d) % 23;
				int b = (Integer.parseInt(parts[1]) + d) % 28;
				int c = (Integer.parseInt(parts[2]) + d) % 33;

				while (a % 28 != b)
					a += 23;
				while (a % 33 != c)
					a += 644; // 23*28
				if (a == 0)
					a = 21252;

				System.out.println("Case " + (++i) + ": the next triple peak occurs in " + a + " days.");
			}
		}
	}

	// -----
	// -----

	public static void main(String[] args) throws Exception {
		Judge.run();
	}

}
